package com.android.sharecar.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

import com.android.sharecar.util.SysUtil;

/**
 * The main UI for user's operating
 * @author xinyan
 *@date 2011-9-13
 */
public class MainTabWidgetActivity extends TabActivity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tabhost_main);

		Resources res = getResources(); // Resource object to get Drawables
		TabHost tabHost = getTabHost(); // The activity TabHost
		TabHost.TabSpec spec; // Reusable TabSpec for each tab
		Intent intent; // Reusable Intent for each tab
		Intent intentForStandard; // For put the state to standard activity.
		Bundle bundle;

		intentForStandard = getIntent();
		bundle = intentForStandard.getExtras();

		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, StandardActivity.class).putExtra(
				"state", bundle.getInt("state"));

		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("standardTab").setIndicator("普通")
				.setContent(intent);
		tabHost.addTab(spec);

		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, PickRideActivity.class);

		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("pickrideTab").setIndicator("搭车")
				.setContent(intent);
		tabHost.addTab(spec);

		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, DrivingAcitvity.class);

		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("drivingTab").setIndicator("开车")
				.setContent(intent);
		tabHost.addTab(spec);

		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, ReserveActivity.class);

		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("reserveTab").setIndicator("预约")
				.setContent(intent);
		tabHost.addTab(spec);

		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, TalkActivity.class);

		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("talkTab").setIndicator("发言")
				.setContent(intent);
		tabHost.addTab(spec);

		tabHost.setCurrentTab(0);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main_interface_menu, menu);

		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int itemId = item.getItemId();

		switch (itemId) {
		case R.id.menu_item_about:
			startActivity(new Intent(this, AboutActivity.class));

			break;

		case R.id.menu_item_exist:
			SysUtil util = new SysUtil(this);
			util.exit(); // exist the entire app directly.

			break;

		case R.id.menu_item_configure:
			startActivity(new Intent(this, ConfigureActivity.class));

			break;

		default:
			break;
		}

		return super.onOptionsItemSelected(item);
	}
}
